var year = 2015;
var month = 11;


var nian = year;
var yue = month;


document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = month;


//总天数
var days = 0;



//判断1970~ 是不是闰年
function runNian(y){
    if (y % 400 === 0 || (y % 4 === 0 && y % 100 !==0)){
        return true;
    }else{
        return false;
    }
}



//算出1970~哪一年的前一年一共有多少天
for(var i = 1980 ; i<year; i++){
    if(runNian(i)){
        days += 366;
    }else{
        days += 365;
    }
}





//今年的1月到这个的上一个月有多少天
/*
 31
 28
 31
 30
 */
for(var j = 1; j < month ;j++){
    switch (j){
        case 1:
            days += 31;
            break;
        case 2:
            if(runNian(year)){
                days += 29;
            }else{
                days += 28;
            }
            break;
        case 3:
            days += 31;
            break;
        case 4:
            days += 30;
            break;
        case 5:
            days += 31;
            break;
        case 6:
            days += 30;
            break;
        case 7:
            days += 31;
            break;
        case 8:
            days += 31;
            break;
        case 9:
            days += 30;
            break;
        case 10:
            days += 31;
            break;
        case 11:
            days += 30;
            break;
        case 12:
            days += 31;
            break;

    }
}





//算出本月多少天
var day = 0;
switch (month){
    case 1:
        day += 31;
        break;
    case 2:
        if(runNian(year)){
            day += 29;
        }else{
            day += 28;
        }
        break;
    case 3:
        day += 31;
        break;
    case 4:
        day += 30;
        break;
    case 5:
        day += 31;
        break;
    case 6:
        day += 30;
        break;
    case 7:
        day += 31;
        break;
    case 8:
        day += 31;
        break;
    case 9:
        day += 30;
        break;
    case 10:
        day += 31;
        break;
    case 11:
        day += 30;
        break;
    case 12:
        day += 31;
        break;

}
console.log(day);








//算出上个月多少天
var topDay = 0;
if(month == 1){
    topDay +=31;
}else{
    switch (month-1){
        case 1:
            topDay += 31;
            break;
        case 2:
            if(runNian(year)){
                topDay += 29;
            }else{
                topDay += 28;
            }
            break;
        case 3:
            topDay += 31;
            break;
        case 4:
            topDay += 30;
            break;
        case 5:
            topDay += 31;
            break;
        case 6:
            topDay+= 30;
            break;
        case 7:
            topDay += 31;
            break;
        case 8:
            topDay += 31;
            break;
        case 9:
            topDay += 30;
            break;
        case 10:
            topDay += 31;
            break;
        case 11:
            topDay += 30;
            break;
        case 12:
            topDay += 31;
            break;

    }
}

console.log(topDay);




days += 2;

console.log(days);

//算出2019年1号是周几
var start = days % 7;
console.log(start);



if(start == 0){
    start += 7;
}


//2019年可以放多少天(算一下当前页面的日历一共可以放多少天)
var num = 42;




//获取当前是几号
var thisDay = new Date().getDate();
console.log(thisDay);



//算出下一个月可以放多少天
var nextDay = num - start - day;
console.log(nextDay);



var day1 = document.querySelector("#day1");

//算出前边空余的是几天
for(var k = topDay - start +1; k <= topDay; k++){
    day1.innerHTML += "<span class='h'>" + k + "</span>";
}



//这个月的天数
for(var a = 1; a <= day; a++){
    if(a == thisDay){
        day1.innerHTML += "<span class='today'>" + a + "</span>";
    }else{
        day1.innerHTML += "<span>" + a + "</span>";
    }
}


//算出下个月的有几天
for(var s = 1; s <= nextDay; s++){
    day1.innerHTML += "<span class='h'>" + s + "</span>";
}



